package com.marquis.cloud.controller;

import com.marquis.cloud.client.PersonClient;
import com.marquis.cloud.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@Configuration
@RequestMapping("/person/")
public class PersonController {

    @Autowired
    private PersonClient personClient;

    @RequestMapping(value = "/findById/{id}")
    @ResponseBody
    public Person test(HttpServletRequest request, @PathVariable int id){
        Person ps = personClient.findById(id);
        String message = ps.getMessage();
        String msg = "provider:"+message+">>caller:"+request.getRequestURL().toString();
        ps.setMessage(msg);
        return ps;
    }

    @RequestMapping(value = "test")
    @ResponseBody
    public String test(){
        return "success";
    }
}
